﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Text;

namespace GmailMetroNotifier.Client.Business
{
    /// <summary>
    /// Provides data for the <see cref="IGmailManager.AuthenticationFailed"/> cancelable event.
    /// </summary>
    public class AuthenticationFailedEventArgs : CancelEventArgs
    {
        /// <summary>
        /// Gets or sets the new credentials to be used in case the authentication should be retried.
        /// </summary>
        public NetworkCredential NewCredential { get; set; }

        /// <summary>
        /// Gets the username used in last authentication attempt.
        /// </summary>
        public string UserName { get; private set; }

        /// <summary>
        /// Gets the password used in last authentication attempt. This value is null if the 
        /// password used before was from <see cref="NetworkCredential.SecurePassword"/>.
        /// </summary>
        public string Password { get; private set; }

        /// <summary>
        /// Initializes a new instance of the class with the <see cref="CancelEventArgs.Cancel"/> property set to false,
        /// and using the specified username and password.
        /// </summary>
        /// <param name="userName">The username used in last authentication attempt.</param>
        /// <param name="password">The password used in last authentication attempt.</param>
        public AuthenticationFailedEventArgs(string userName, string password)
            : this(userName, password, false)
        {
            
        }

        /// <summary>
        /// Initializes a new instance of the class with the <see cref="CancelEventArgs.Cancel"/> property set to the given value,
        /// and using the specified username and password.
        /// </summary>
        /// <param name="userName">The username used in last authentication attempt.</param>
        /// <param name="password">The password used in last authentication attempt.</param>
        /// <param name="cancel">The initial value of the <see cref="CancelEventArgs.Cancel"/> property.</param>
        public AuthenticationFailedEventArgs(string userName, string password, bool cancel)
            : base(cancel)
        {
            this.UserName = userName;

            this.Password = password;

            this.NewCredential = new NetworkCredential();
        }
    }
}
